package cn.com.header.zbpk.base.controller;

import cn.com.header.core.support.web.JsonViewData;
import cn.com.header.zbpk.base.entity.Section;
import cn.com.header.zbpk.base.service.ISectionService;
import cn.com.header.zbpk.web.CommonController;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 学段控制器
 * @author Yuanyifeng
 * @date 2017-11-21
 * @time 17:41
 */
@RestController
@RequestMapping(value = "/base/section")
        public class SectionController extends CommonController{
    @Autowired
    private ISectionService iSectionService;
    /**
     * 获取学段
     * @return
     */
    @RequestMapping(value="getSection")
    public JsonViewData getSection(){
        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(1);
        Section section=new Section();
        if(getCurrentUser()!=null){
            section.setSchoolId(getCurrentUser().getSchoolId());
            List<Section> sectionList=iSectionService.loads(section,false, Sets.newHashSet("id","name"));
            resultMap.put("sectionList",sectionList);
            return setJsonViewData(resultMap);
        }else{
            return setJsonViewData("用户未登录");
        }
    }
}
